﻿package mortal.game.view.FirstRechargeDay500
{
    import Message.Public.*;
    import com.mui.controls.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.item.*;
    import mortal.game.view.signUp.sevenDayLogin.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class FirstRechargeDay500Module extends ActivityBaseWindow
    {
        protected var _togoBtn:GLoadingButton;
        protected var _list:CellsGridSprite;
        protected var _getBtn:GLoadingButton;
        private var _info:Object;
        private static var _instance:FirstRechargeDay500Module;

        public function FirstRechargeDay500Module(param1:ILayer = null, param2:String = "", param3:String = "")
        {
            setSize(696, 412);
            super(param1, ImagesConst.FirstRechargeDay500Title, ImagesConst.FirstRechargeDay500Bg);
            return;
        }// end function

        override protected function configParams() : void
        {
            _titleSpriteHight = 120;
            super.configParams();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._togoBtn = UIFactory.gLoadingButton(ImagesConst.FirstRechargeDay500Btn_upSkin, 255, 387, 187, 54, this);
            this._togoBtn.label = "";
            this._list = UIFactory.getUICompoment(CellsGridSprite);
            this._list.colNum = 4;
            this._list.vCellWid = 75;
            this._list.hCellWid = 100;
            this._list.genCellFun = this.genItem;
            this._list.genCells(4);
            this._list.x = 334;
            this._list.y = 250;
            this.addChild(this._list);
            this._getBtn = UIFactory.gLoadingButton(ImagesConst.FirstRechargeDay500GetWBtn_upSkin, 255, 387, 187, 54, this);
            this._getBtn.label = "";
            this._getBtn.visible = false;
            this.updateRw();
            this.updateBtn();
            this._togoBtn.configEventListener(MouseEvent.CLICK, this.gotoRc);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onCk);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.setBtn(true);
            SevenDayLoginUtil.showGuideArrow(this._togoBtn, false, this);
            this._togoBtn = null;
            this._list = null;
            this._getBtn = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function genItem() : RebateItem
        {
            var _loc_1:* = UIFactory.getUICompoment(RebateItem);
            return _loc_1;
        }// end function

        private function updateRw() : void
        {
            var _loc_7:SPlayerItem = null;
            var _loc_8:RebateItem = null;
            var _loc_1:* = RebateUtil.getDayRechargeList();
            if (_loc_1 == null || _loc_1.length == 0)
            {
                return;
            }
            this._info = _loc_1[0];
            var _loc_2:* = this._info.giftBag;
            var _loc_3:* = ItemConfig.instance.getConfig(_loc_2);
            if (_loc_3 == null)
            {
                return;
            }
            var _loc_4:* = _loc_3.itemList1;
            var _loc_5:* = QuestionCopyConfig.instance().getRewardItems(_loc_4);
            if (_loc_5 == null || _loc_5.length == 0)
            {
                return;
            }
            this._list.genCells(_loc_5.length);
            var _loc_6:int = 0;
            while (_loc_6 < _loc_5.length)
            {
                
                _loc_7 = _loc_5[_loc_6];
                _loc_8 = this._list.cellArr[_loc_6];
                _loc_8.updateInfo(_loc_7);
                _loc_6++;
            }
            return;
        }// end function

        public function updateBtn() : void
        {
            var _loc_1:* = RebateUtil.dayRechargeArr[0];
            if (Cache.instance.rebate.dayRechargeInfo == null)
            {
                return;
            }
            var _loc_2:* = RebateUtil.getRwState(0);
            switch(_loc_2[0])
            {
                case 0:
                {
                    this._getBtn.visible = false;
                    this._togoBtn.visible = true;
                    break;
                }
                case 1:
                {
                    this._getBtn.visible = true;
                    this._togoBtn.visible = false;
                    break;
                }
                case 2:
                {
                    this._getBtn.visible = false;
                    this._togoBtn.visible = true;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function setBtn(param1:Boolean) : void
        {
            if (param1)
            {
                this._togoBtn.enabled = true;
                this._togoBtn.filters = null;
                SevenDayLoginUtil.showGuideArrow(this._togoBtn, true, this);
            }
            else
            {
                SevenDayLoginUtil.showGuideArrow(this._togoBtn, false, this);
                this._togoBtn.enabled = false;
                this._togoBtn.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        private function onCk(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            if (hasRw())
            {
                _loc_2 = RebateUtil.dayRechargeArr[0];
                Dispatcher.dispatchEvent(new DataEvent(EventName.RebateDayRechargeGetReward, _loc_2));
            }
            return;
        }// end function

        private function gotoRc(event:MouseEvent) : void
        {
            GameUtil.gotoRecharge(ModuleTypeConst.FirstRecharge500);
            return;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function get instance() : FirstRechargeDay500Module
        {
            if (!_instance)
            {
                _instance = new FirstRechargeDay500Module;
            }
            return _instance;
        }// end function

        public static function hasRw() : Boolean
        {
            var _loc_1:* = RebateUtil.getRwState(0);
            return _loc_1[0] == 1;
        }// end function

        public static function getRWstate() : Boolean
        {
            var _loc_1:* = RebateUtil.getRwState(0);
            return _loc_1[1] < _loc_1[2];
        }// end function

    }
}
